<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import echarts from 'echarts'

require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import mapData from './liaoning.json'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      echarts.registerMap('LN',mapData)
      this.chart.setOption({
          title: {
            text: '辽宁省各市重点站数量(20211116)',
            subtext: 'Data from CSV'
          },
          tooltip: {
            trigger: 'item',
            formatter: '{b}<br/>{c}'
          },
          toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
              dataView: { readOnly: false },
              restore: {},
              saveAsImage: {}
            }
          },
          visualMap: {
            min: 100,
            max: 1500,
            text: ['High', 'Low'],
            realtime: false,
            calculable: true,
            inRange: {
              color: ['lightskyblue', 'yellow', 'orangered']
            }
          },
          series: [
            {
              name: '辽宁各市重点站数量',
              type: 'map',
              map: 'LN',
              label: {
                show: true
              },
              data: [
                {
                  'name': '鞍山市',
                  'value': 299
                },
                {
                  'name': '本溪市',
                  'value': 171
                },
                {
                  'name': '朝阳市',
                  'value': 287
                },
                {
                  'name': '大连市',
                  'value': 1248
                },
                {
                  'name': '丹东市',
                  'value': 199
                },
                {
                  'name': '抚顺市',
                  'value': 206
                },
                {
                  'name': '阜新市',
                  'value': 212
                },
                {
                  'name': '葫芦岛市',
                  'value': 231
                },
                {
                  'name': '锦州市',
                  'value': 245
                },
                {
                  'name': '辽阳市',
                  'value': 151
                },
                {
                  'name': '盘锦市',
                  'value': 124
                },
                {
                  'name': '沈阳市',
                  'value': 1220
                },
                {
                  'name': '铁岭市',
                  'value': 305
                },
                {
                  'name': '营口市',
                  'value': 320
                }
              ]
            }
          ]
        }
      )
    }
  }
}
</script>
